import pymysql

conn = pymysql.connect(
    host='192.168.88.161',
    port=3306,
    user='root',
    password='123456',
    db='bigdata',
    charset='utf8mb4',
    cursorclass=pymysql.cursors.DictCursor
)

cursor = conn.cursor()

def querymysql(sql, params, type='no_select'):
    try:
        params = tuple(params)
        cursor.execute(sql, params)
        if type != 'no_select':
            data_list = cursor.fetchall()
            conn.commit()
            return data_list
        else:
            conn.commit()
            return '数据库语句执行成功'
    except Exception as e:
        print(f"MySQL查询错误: {e}")
        conn.rollback()
        raise e